package com.shujia.wyh.mr.youhua;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MyWeatherMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        //2008-02-25 18:05:14	21
        String line = value.toString();
        String[] strings = line.split("\t");
        String time = strings[0];
        String temperature = strings[1];

        String[] strings2 = time.split(" ")[0].split("-");
        String year = strings2[0];
        String month = strings2[1];
        if("02".equals(month)){
            context.write(new Text(year+"-"+month),new LongWritable(Long.parseLong(temperature)));
        }
    }
}
